<?php
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php';
/**
 *向(决策系统)dms同步产品新品标示
 *@author shipanpan
 */
class SynNewProductMarkController extends Controller_CronJob {
	public function run($value = '') {
		$dmsDb = Model_Db::getInstance('dms_db');
		$ifsDb = Model_Db::getInstance('write_db');
		$today = date("Y-m-d");
		$yesterday = date("Y-m-d", strtotime("-1 day"));

		$where = "calculate_date='" . $yesterday . "'  AND sku!='' AND stock_code!=''";
		$todayHasCalculateNum = $dmsDb->fetchOne("select count(*) from public_erp_re_decision_new_sku where $where");

		if (!$todayHasCalculateNum) {
			$this->log->record("决策系统未有" . $today . ' 日新品统计数据！', Log::ERR);
			exit;
		}

		$everyTimeHandleRow = 40000;
		$handleTimes = ceil($todayHasCalculateNum / $everyTimeHandleRow);

		for ($i = 0; $i < $handleTimes; $i++) {
			$offset = $i * $everyTimeHandleRow;

			$productList = $dmsDb->fetchAll('select sku as goods_sn,type as is_new,stock_code as warehouse,create_time as is_new_update_time from public_erp_re_decision_new_sku  where ' . $where . " limit $offset,$everyTimeHandleRow ");

			foreach ($productList as $_oneProduct) {
				Model_Base::insertOrUpdate($ifsDb, 'p_warehouse_product', $_oneProduct);
			}

		}
	}
}

$synNewProductMark = new SynNewProductMarkController();
$synNewProductMark->run();